﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using UofCASE.GreenPepe.Extensibility;
using System.IO;
using System.Windows.Media.Imaging;
using System.ComponentModel;

namespace UofCASE.AgileProductLinerDSL {
    public class MappingTreeNode {

        private object dataContent;
        private ObservableCollection<MappingTreeNode> children = new ObservableCollection<MappingTreeNode>();
        private String name;
        private bool isExpanded;

        public event EventHandler IconChanged;

        protected void OnIconChanged(){
            if (IconChanged != null){
                IconChanged(this, new EventArgs());
            }
        }

        public MappingTreeNode(TestInformation testInfo) {
            this.dataContent = testInfo;
            Name = new FileInfo(testInfo.RelativePath).Name;
            IsFolder = false;
        }

        public MappingTreeNode(String folderName) {
            this.dataContent = "";
            this.Name = folderName;
            IsFolder = true;
        }

        public bool IsFolder {
            get; set;
        }

        public bool IsExpanded {
            get{
                return this.isExpanded;
            }
            set {
                this.isExpanded = value;
                OnIconChanged();
            }
        }

        public BitmapImage Icon {
            get {
                return FolderTestIconConverter.GetImage(this);
            }
        }

        public String Name {
            get { return name; }
            set { name = value; }
        }

        public ObservableCollection<MappingTreeNode> Children {
            get { return children; }
            set { children = value; }
        }
        
        public object DataContent {
            get { return dataContent; }
            set { dataContent = value; }
        }

        public bool IsMapped {
            get {
                if (!IsFolder) {
                    TestInformation testInfo = dataContent as TestInformation;
                    return testInfo.IsMapped;
                } else return false;
            }
        }
    }
}
